/*
 * Copyright 2009-2010 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.alias.objectsource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.Icon;

import org.kommando.core.catalog.AbstractObjectSource;
import org.kommando.core.catalog.CatalogObject;
import org.kommando.core.catalog.ObjectSource;

/**
 * {@link ObjectSource} that holds the aliases.
 * 
 * @author Peter De Bruycker
 */
public class AliasObjectSource extends AbstractObjectSource {

    private static final String ID = "alias:aliases";

    // TODO store CatalogObject.id instead of CatalogObject itself

    private Map<CatalogObject, String> aliases = new HashMap<CatalogObject, String>();

    @Override
    public String getDescription() {
        // TODO description
        return "TODO";
    }

    @Override
    public Icon getIcon() {
        // TODO icon
        return null;
    }

    @Override
    public String getId() {
        return ID;
    }

    @Override
    public String getName() {
        return "Aliases";
    }

    @Override
    public List<CatalogObject> getObjects() {
        List<CatalogObject> objects = new ArrayList<CatalogObject>();

        for (Map.Entry<CatalogObject, String> alias : aliases.entrySet()) {
            objects.add(new AliasObject(alias.getKey(), alias.getValue()));
        }

        return objects;
    }

    public void setAlias(CatalogObject direct, String text) {
        aliases.put(direct, text);
    }

    public boolean hasAlias(CatalogObject object) {
        return aliases.containsKey(object);
    }

    public void removeAlias(CatalogObject object) {
        aliases.remove(object);
    }
}
